﻿package core.ui.options
{
    import core.event.*;
    import core.ui.controls.*;
    import core.ui.util.*;
    import flash.display.*;
    import flash.events.*;
    import flash.filters.*;

    public class BevelOptions extends Sprite
    {
        var p:Tuyitu;
        var filter:BevelFilter;
        public var style:Dropdown;
        public var highlightopacity:Slidebar;
        public var shadowopacity:Slidebar;
        public var distance:Slidebar;
        public var size:Slidebar;
        public var angle:DegreeSelector;
        public var highlightcolor:ColorPad;
        public var shadowcolor:ColorPad;

        public function BevelOptions(param1:Tuyitu, param2:BevelFilter)
        {
            this.p = param1;
            this.filter = param2;
            var _loc_3:* = new Literal("rm_style");
            _loc_3.x = 80 - _loc_3.width - 2;
            _loc_3.y = 0;
            addChild(_loc_3);
            this.distance = new Slidebar("rm_distance", 0, 100, 100, param2.distance, true);
            this.distance.addEventListener(SliderEvent.DRAG, this.ValueChange, false, 1, true);
            this.distance.x = 80;
            this.distance.y = 25;
            addChild(this.distance);
            this.size = new Slidebar("rm_size", 0, 100, 100, param2.blurX, true);
            this.size.addEventListener(SliderEvent.DRAG, this.ValueChange, false, 1, true);
            this.size.x = 80;
            this.size.y = 50;
            addChild(this.size);
            this.angle = new DegreeSelector("rm_angle", param2.angle - 180);
            this.angle.addEventListener(SliderEvent.DRAG, this.ValueChange, false, 1, true);
            this.angle.x = 80;
            this.angle.y = 85;
            addChild(this.angle);
            var _loc_4:* = new Literal("rm_highlights");
            _loc_4.x = -10;
            _loc_4.y = 120;
            addChild(_loc_4);
            var _loc_5:* = new Literal("rm_color");
            _loc_5.x = 80 - _loc_5.width - 2;
            _loc_5.y = 140;
            addChild(_loc_5);
            this.highlightcolor = new ColorPad(param2.highlightColor, true);
            this.highlightcolor.addEventListener(MouseEvent.MOUSE_DOWN, this.ColorMouseDown, false, 1, true);
            this.highlightcolor.addEventListener(ColorPadEvent.CHOOSE_COLOR, this.ValueChange, false, 1, true);
            this.highlightcolor.x = 80;
            this.highlightcolor.y = 140;
            addChild(this.highlightcolor);
            this.highlightopacity = new Slidebar(U.RM("rm_opacity"), 0, 100, 100, Math.round(param2.highlightAlpha * 100), true);
            this.highlightopacity.addEventListener(SliderEvent.DRAG, this.ValueChange, false, 1, true);
            this.highlightopacity.x = 80;
            this.highlightopacity.y = 155;
            addChild(this.highlightopacity);
            var _loc_6:* = new Literal("rm_shadows");
            _loc_6.x = -10;
            _loc_6.y = 185;
            addChild(_loc_6);
            var _loc_7:* = new Literal("rm_color");
            _loc_7.x = 80 - _loc_7.width - 2;
            _loc_7.y = 205;
            addChild(_loc_7);
            this.shadowcolor = new ColorPad(param2.shadowColor, true);
            this.shadowcolor.addEventListener(MouseEvent.MOUSE_DOWN, this.ColorMouseDown, false, 1, true);
            this.shadowcolor.addEventListener(ColorPadEvent.CHOOSE_COLOR, this.ValueChange, false, 1, true);
            this.shadowcolor.x = 80;
            this.shadowcolor.y = 205;
            addChild(this.shadowcolor);
            this.shadowopacity = new Slidebar(U.RM("rm_opacity"), 0, 100, 100, Math.round(param2.shadowAlpha * 100), true);
            this.shadowopacity.addEventListener(SliderEvent.DRAG, this.ValueChange, false, 1, true);
            this.shadowopacity.x = 80;
            this.shadowopacity.y = 220;
            addChild(this.shadowopacity);
            this.style = new Dropdown(90, 90);
            this.style.addEventListener(SelectEvent.COMMAND, this.ValueChange, false, 1, true);
            this.style.x = 80;
            this.style.y = 0;
            this.style.AddItem(U.RM("rm_inner"), "inner", true);
            this.style.AddItem(U.RM("rm_outer"), "outer");
            this.style.AddItem(U.RM("rm_full"), "full");
            this.style.Bind();
            addChild(this.style);
            return;
        }// end function

        public function ColorMouseDown(event:MouseEvent) : void
        {
            new ColorPicker(this.p, event.target as ColorPad);
            return;
        }// end function

        public function ValueChange(... args) : void
        {
            this.filter.type = this.style.value;
            this.filter.highlightColor = this.highlightcolor.value;
            this.filter.highlightAlpha = this.highlightopacity.value / 100;
            this.filter.shadowColor = this.shadowcolor.value;
            this.filter.shadowAlpha = this.shadowopacity.value / 100;
            this.filter.distance = this.distance.value;
            args = this.size.value;
            this.filter.blurY = args;
            this.filter.blurX = args;
            this.filter.angle = this.angle.value + 180;
            dispatchEvent(new ChangeEvent("update"));
            return;
        }// end function

    }
}
